﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.Infra.Common;
using Sinacor.Infra.UI.Authorization.Infra.Authorization.Policy;

namespace Sinacor.Infra.UI.Authorization.Policy.Translator
{
    public class BehaviorPolicyResponseToBehaviorPolicy :
        BaseTranslator<Entity.BehaviorPolicy, BehaviorPolicyResponse, List<Entity.BehaviorPolicy>, List<BehaviorPolicyResponse>>
    {

        public override Entity.BehaviorPolicy Translate(BehaviorPolicyResponse from)
        {
            if (from == null)
                return null;

            Entity.BehaviorPolicy to = new Entity.BehaviorPolicy();
            to.Policy = new Entity.Policy();
            to.Policy.PolicyId = from.AssociatedPolicy.PolicyId;
            to.Policy.PolicyName = from.AssociatedPolicy.PolicyName;


            if (from.AssociatedPolicy != null)
            {
                Entity.Enum.PolicyStatus? status;
                Translator.Enum.PolicyStatusTranslator.Translate(from.AssociatedPolicy.PolicyStatus, out status);
                to.Policy.PolicyStatus = status;

                Entity.Enum.PolicyType? type;
                Translator.Enum.PolicyTypeTranslator.Translate(from.AssociatedPolicy.PolicyType, out type);
                to.Policy.PolicyType = type;
            }

            to.RoleId = from.RoleId;

            to.IsEditable = from.IsEditable;
            to.IsVisible = from.IsVisible;

            return to;
        }
    }
}
